```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java文件操作完全指南 | 技术小馆</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        h1, h2, h3, h4, h5, h6 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
        }
        .hero {
            background: linear-gradient(135deg, #6B73FF 0%, #000DFF 100%);
            color: white;
        }
        .code-block {
            background-color: #2d2d2d;
            color: #f8f8f2;
            border-radius: 8px;
            position: relative;
        }
        .code-header {
            background-color: #1e1e1e;
            border-top-left-radius: 8px;
            border-top-right-radius: 8px;
            padding: 8px 16px;
            color: #9e9e9e;
            font-size: 0.9rem;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        .copy-btn {
            background: none;
            border: none;
            color: #9e9e9e;
            cursor: pointer;
            transition: all 0.2s;
        }
        .copy-btn:hover {
            color: white;
        }
        .method-card {
            transition: all 0.3s ease;
            border-left: 4px solid #6B73FF;
        }
        .method-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
        }
        .footer {
            background-color: #1a1a1a;
            color: #e0e0e0;
        }
        .footer a:hover {
            color: #6B73FF;
        }
        .mermaid-container {
            background-color: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            margin: 2rem 0;
        }
        .table-container {
            overflow-x: auto;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero py-20 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl text-center">
            <h1 class="text-4xl md:text-5xl font-bold mb-6">Java文件操作完全指南</h1>
            <p class="text-xl md:text-2xl mb-8 opacity-90">掌握Java文件处理的核心方法与最佳实践</p>
            <div class="flex justify-center space-x-4">
                <span class="px-4 py-2 bg-white bg-opacity-20 rounded-full">
                    <i class="fas fa-file-alt mr-2"></i>文件操作
                </span>
                <span class="px-4 py-2 bg-white bg-opacity-20 rounded-full">
                    <i class="fas fa-code mr-2"></i>Java编程
                </span>
                <span class="px-4 py-2 bg-white bg-opacity-20 rounded-full">
                    <i class="fas fa-database mr-2"></i>IO流
                </span>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto max-w-5xl py-12 px-4 md:px-0">
        <!-- Introduction -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-6 text-gray-800">文件操作基础知识</h2>
            <p class="text-lg text-gray-700 mb-6">Java的<code>java.io.File</code>类提供了丰富的文件操作功能，包括文件创建、删除、遍历目录、读写文件内容等。掌握这些方法是Java开发者的必备技能。</p>
            
            <div class="bg-blue-50 border-l-4 border-blue-500 p-6 rounded-r-lg mb-8">
                <div class="flex items-start">
                    <div class="flex-shrink-0 text-blue-500 mt-1 mr-4">
                        <i class="fas fa-info-circle text-xl"></i>
                    </div>
                    <div>
                        <h4 class="font-bold text-blue-800 mb-2">关键概念</h4>
                        <p class="text-blue-700">File类不仅可以代表文件，也可以代表目录。在使用时需要注意路径分隔符在不同操作系统中的区别。</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Methods Table -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-6 text-gray-800">File类常用方法</h2>
            <div class="table-container">
                <table class="min-w-full bg-white rounded-lg overflow-hidden">
                    <thead class="bg-gray-100">
                        <tr>
                            <th class="py-3 px-4 text-left font-semibold text-gray-700">序号</th>
                            <th class="py-3 px-4 text-left font-semibold text-gray-700">方法或常量</th>
                            <th class="py-3 px-4 text-left font-semibold text-gray-700">类型</th>
                            <th class="py-3 px-4 text-left font-semibold text-gray-700">描述</th>
                        </tr>
                    </thead>
                    <tbody class="divide-y divide-gray-200">
                        <tr class="hover:bg-gray-50">
                            <td class="py-4 px-4">1</td>
                            <td class="py-4 px-4 font-mono text-blue-600">public static final String pathSeparator</td>
                            <td class="py-4 px-4">常量</td>
                            <td class="py-4 px-4">表示路径的分隔符(windows是："；"）</td>
                        </tr>
                        <tr class="hover:bg-gray-50">
                            <td class="py-4 px-4">2</td>
                            <td class="py-4 px-4 font-mono text-blue-600">public static final String separator</td>
                            <td class="py-4 px-4">常量</td>
                            <td class="py-4 px-4">表示路径分隔符(widnows是："\"）</td>
                        </tr>
                        <tr class="hover:bg-gray-50">
                            <td class="py-4 px-4">3</td>
                            <td class="py-4 px-4 font-mono text-blue-600">public booelan createNewFile() throws IoException</td>
                            <td class="py-4 px-4">普通</td>
                            <td class="py-4 px-4 font-semibold">创建新的文件</td>
                        </tr>
                        <tr class="hover:bg-gray-50">
                            <td class="py-4 px-4">4</td>
                            <td class="py-4 px-4 font-mono text-blue-600">public boolean mkdir()</td>
                            <td class="py-4 px-4">普通</td>
                            <td class="py-4 px-4">创建目录</td>
                        </tr>
                        <tr class="hover:bg-gray-50">
                            <td class="py-4 px-4">5</td>
                            <td class="py-4 px-4 font-mono text-blue-600">public File[] listFiles()</td>
                            <td class="py-4 px-4">普通</td>
                            <td class="py-4 px-4">列出指定目录的全部内容，会列出路径</td>
                        </tr>
                        <tr class="hover:bg-gray-50">
                            <td class="py-4 px-4">6</td>
                            <td class="py-4 px-4 font-mono text-blue-600">public String[] list()</td>
                            <td class="py-4 px-4">普通</td>
                            <td class="py-4 px-4">列出指定目录的全部内容，只是列出名称</td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </section>

        <!-- Visual Diagram -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-6 text-gray-800">文件操作流程</h2>
            <div class="mermaid-container">
                <div class="mermaid">
                    flowchart TD
                        A[创建File对象] --> B{是文件还是目录?}
                        B -->|文件| C[执行文件操作\ncreateNewFile\n读写内容等]
                        B -->|目录| D[执行目录操作\nmkdir\nlistFiles\nlist等]
                        C --> E[关闭流资源]
                        D --> F[递归处理子目录]
                </div>
            </div>
            <p class="text-gray-600 mt-4">流程图展示了Java文件操作的基本流程，包括文件和目录的不同处理方式以及资源管理的重要性。</p>
        </section>

        <!-- Code Examples -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-6 text-gray-800">代码示例</h2>

            <!-- Example 1 -->
            <div class="mb-12">
                <h3 class="text-2xl font-semibold mb-4 text-gray-700">1. 测试createNewFile()方法</h3>
                <div class="code-block">
                    <div class="code-header">
                        <span>Java</span>
                        <button class="copy-btn" onclick="copyCode(this)">
                            <i class="far fa-copy mr-1"></i>复制代码
                        </button>
                    </div>
                    <pre class="p-4 overflow-x-auto"><code>public class Tese01 {
    public static void main(String[] args) {
        File file = new File("F:/file.txt");
        boolean createNewFile;
        try {
            createNewFile = file.createNewFile(); //创建文本文件
            System.out.println(createNewFile);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}</code></pre>
                </div>
            </div>

            <!-- Example 2 -->
            <div class="mb-12">
                <h3 class="text-2xl font-semibold mb-4 text-gray-700">2. list()和listFiles()的区别</h3>
                <div class="code-block">
                    <div class="code-header">
                        <span>Java</span>
                        <button class="copy-btn" onclick="copyCode(this)">
                            <i class="far fa-copy mr-1"></i>复制代码
                        </button>
                    </div>
                    <pre class="p-4 overflow-x-auto"><code>public class Tese01 {
    public static void main(String[] args) {
        File file = new File("F:/");
        
        String[] list = file.list(); // 列出名称
        System.out.println("字符串类型：");
        for (String string : list) {
            System.out.println(string);
        }
        
        File[] listFiles = file.listFiles(); // 列出完整的路径
        System.out.println("File类型：");
        for(File fi :listFiles){
            System.out.println(fi);
        }
    }
}</code></pre>
                </div>
            </div>

            <!-- Example 3 -->
            <div class="mb-12">
                <h3 class="text-2xl font-semibold mb-4 text-gray-700">3. 列出一个目录下的全部文件</h3>
                <div class="code-block">
                    <div class="code-header">
                        <span>Java</span>
                        <button class="copy-btn" onclick="copyCode(this)">
                            <i class="far fa-copy mr-1"></i>复制代码
                        </button>
                    </div>
                    <pre class="p-4 overflow-x-auto"><code>public class Tese01 {
    public static void main(String[] args) {
        File file = new File("E:/第五组/");
        pritn(file);
    }
    public static void pritn(File file) {
        if (file.isDirectory()) { // 判断是否是一个路径
            File[] listFiles = file.listFiles(); // 如果是目录列出目录的全部内容
            for (File file2 : listFiles) {  
                pritn(file2); // 递归调用
            }
        } else {
            System.out.println(file); // 不是路径，直接打印信息
        }
    }
}</code></pre>
                </div>
            </div>

            <!-- Example 4 -->
            <div class="mb-12">
                <h3 class="text-2xl font-semibold mb-4 text-gray-700">4. 向文件中追加内容</h3>
                <div class="code-block">
                    <div class="code-header">
                        <span>Java</span>
                        <button class="copy-btn" onclick="copyCode(this)">
                            <i class="far fa-copy mr-1"></i>复制代码
                        </button>
                    </div>
                    <pre class="p-4 overflow-x-auto"><code>public class Tese01 {
    public static void main(String[] args) {
        File file = new File("E:/file.txt");
        FileOutputStream out = null;
        try {
            out = new FileOutputStream(file, true); // true,表示在文件末尾追加内容
            String str = "hello World \r\n";     // 加入换行
            byte[] bytes = str.getBytes();
            out.write(bytes);
        } catch (Exception e) {
            e.printStackTrace();
        } finally{
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}</code></pre>
                </div>
            </div>

            <!-- Example 5 -->
            <div class="mb-12">
                <h3 class="text-2xl font-semibold mb-4 text-gray-700">5. 读取文件操作</h3>
                <div class="code-block">
                    <div class="code-header">
                        <span>Java</span>
                        <button class="copy-btn" onclick="copyCode(this)">
                            <i class="far fa-copy mr-1"></i>复制代码
                        </button>
                    </div>
                    <pre class="p-4 overflow-x-auto"><code>public class Tese01 {
    public static void main(String[] args) {
        File file = new File("E:/file.txt");
        FileInputStream out = null;
        try {
            out = new FileInputStream(file); // true,表示在文件末尾追加内容
            byte[] bytes = new byte[1024];  // 将所有的内容读到次数组里
            int len = out.read(bytes); // 返回读的字节
            System.out.println(new String(bytes,0, len));
        } catch (Exception e) {
            e.printStackTrace();
        } finally{
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}</code></pre>
                </div>
            </div>

            <!-- Example 6 -->
            <div class="mb-12">
                <h3 class="text-2xl font-semibold mb-4 text-gray-700">6. 文件的拷贝</h3>
                <div class="code-block">
                    <div class="code-header">
                        <span>Java</span>
                        <button class="copy-btn" onclick="copyCode(this)">
                            <i class="far fa-copy mr-1"></i>复制代码
                        </button>
                    </div>
                    <pre class="p-4 overflow-x-auto"><code>public class Tese01 {
    public static void main(String[] args) {
        InputStream ips = null;
        OutputStream ops = null;
        try {
            ips = new FileInputStream(new File("D:" + File.separator + "用户目录"
                + File.separator + "Pictures" + File.separator + "我喜欢"
                + File.separator + "psb.jpg1.jpg"));
            ops = new FileOutputStream(new File("F:"+File.separator +"拷贝的照片.jpg"));
            byte[] by = new byte[1024];
            int read = 0;
            while ((read = ips.read(by, 0, by.length)) > 0) {
                ops.write(by, 0, read);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                ips.close();
                ips.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}</code></pre>
                </div>
            </div>
        </section>

        <!-- Best Practices -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-6 text-gray-800">最佳实践</h2>
            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-white p-6 rounded-lg shadow-md method-card">
                    <div class="flex items-center mb-4">
                        <div class="bg-blue-100 p-3 rounded-full mr-4">
                            <i class="fas fa-check-circle text-blue-500 text-xl"></i>
                        </div>
                        <h3 class="text-xl font-semibold">使用try-with-resources</h3>
                    </div>
                    <p class="text-gray-700">Java 7+引入了try-with-resources语句，可以自动关闭流资源，避免资源泄漏。</p>
                </div>
                <div class="bg-white p-6 rounded-lg shadow-md method-card">
                    <div class="flex items-center mb-4">
                        <div class="bg-blue-100 p-3 rounded-full mr-4">
                            <i class="fas fa-exclamation-triangle text-blue-500 text-xl"></i>
                        </div>
                        <h3 class="text-xl font-semibold">处理异常</h3>
                    </div>
                    <p class="text-gray-700">文件操作可能会抛出IOException，务必妥善处理异常情况。</p>
                </div>
                <div class="bg-white p-6 rounded-lg shadow-md method-card">
                    <div class="flex items-center mb-4">
                        <div class="bg-blue-100 p-3 rounded-full mr-4">
                            <i class="fas fa-lock text-blue-500 text-xl"></i>
                        </div>
                        <h3 class="text-xl font-semibold">权限检查</h3>
                    </div>
                    <p class="text-gray-700">在操作文件前检查文件和目录的读写权限，避免运行时错误。</p>
                </div>
                <div class="bg-white p-6 rounded-lg shadow-md method-card">
                    <div class="flex items-center mb-4">
                        <div class="bg-blue-100 p-3 rounded-full mr-4">
                            <i class="fas fa-globe text-blue-500 text-xl"></i>
                        </div>
                        <h3 class="text-xl font-semibold">跨平台路径</h3>
                    </div>
                    <p class="text-gray-700">使用<code>File.separator</code>代替硬编码的路径分隔符，确保代码跨平台兼容。</p>
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="footer py-8">
        <div class="container mx-auto max-w-5xl px-4 md:px-0">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-4 md:mb-0">
                    <h3 class="text-xl font-semibold">技术小馆</h3>
                    <p class="text-gray-400">专注于高质量的技术分享</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="hover:text-blue-400 transition-colors">
                        <i class="fas fa-external-link-alt mr-2"></i>访问技术小馆语雀
                    </a>
                </div>
            </div>
        </div>
    </footer>

    <script>
        // Initialize Mermaid
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });

        // Copy code function
        function copyCode(button) {
            const codeBlock = button.closest('.code-block').querySelector('pre code');
            const range = document.createRange();
            range.selectNode(codeBlock);
            window.getSelection().removeAllRanges();
            window.getSelection().addRange(range);
            document.execCommand('copy');
            window.getSelection().removeAllRanges();
            
            const originalText = button.innerHTML;
            button.innerHTML = '<i class="fas fa-check mr-1"></i>已复制';
            setTimeout(() => {
                button.innerHTML = originalText;
            }, 2000);
        }
    </script>
</body>
</html>
```